import ala from 'ala'






/*
* 添加wiki
* @viewModel wiki数据，包括project和wikis
* @fatherWiki 沙漠上一级
*/
export async function wikiAdd (viewModel, fatherWiki) {
  var para = {
    name: '新文档' + parseInt(Math.random() * (1000), 10),
    projectId: viewModel.project.id,
    level: 1,
    content: '# 新文档标题',
    sortOrder: 1000,
    userId: ala.userId()
  }

  if (fatherWiki) {
    para.fatherId = fatherWiki.id
    para.level = fatherWiki.level + 1
  }

  var response = await ala.httpPost('Api/Wiki/QuerySave', para)
  if (response) {
    ala.toast('添加成功')
    response.children = []
    viewModel.wikis = ala.arrayDeepAdd(viewModel.wikis, response)
  }
  var result = {
    wikis: viewModel.wikis,
    wikiAdd: response
  }
  return result
}